#!/usr/bin/env python

# Copyright 2011 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Database Initializer."""

from google.appengine.dist import use_library
use_library('django', '1.2')

import logging
from google.appengine.ext import webapp

import model

__author__ = "Maciej Machulak"
__maintainer__ = "Maciej Machulak"
__email__ = "mmachulak@google.com"

__copyright__ = "Copyright 2011, Google Inc."
__license__ = "Apache License 2.0"
__version__ = "0.1"
__status__ = "Prototype"

class DBSetupHandler(webapp.RequestHandler):
    
    def get(self):
      logging.info('db_setup')
      self.setup_db()

    def setup_db(self):
   
      application = model.Application(
          name = 'Street Identity RP',
          client_id = 's_rp_id',
          client_secret = 's_rp_idp_secret',
          redirect_uri = 'http://rp.com:9000/oauth/redirect',
          public_key_url = 'http://rp.com:9000/certs')
      application.put()
      logging.info('Application \' %s \'put under key: %s' % (application.name,application.key()))  

      application = model.Application(
          name = 'Street Identity AP',
          client_id = 's_ap_id',
          client_secret = 's_ap_idp_secret',
          redirect_uri = 'http://ap.com:9002/oauth/redirect',
          public_key_url = 'http://ap.com:9002/certs')
      application.put()
      logging.info('Application \' %s \'put under key: %s' % (application.name,application.key()))  
      
      scope = model.Scope(
          id = 'openid',
          desc = 'Read your profile information',
          icon = 'http://idp.com:9000/static/icons/openid.png')
      scope.put()
      logging.info('Scope \' %s \'put under key: %s' % (scope.id,scope.key()))  
      
      scope = model.Scope(
          id = 'streetaddress_read',
          desc = 'Read your verified street addresses',
          icon = 'http://idp.com:9000/static/icons/streetaddress_read.png')
      scope.put()     
      logging.info('Scope \' %s \'put under key: %s' % (scope.id,scope.key()))  
                      
      scope = model.Scope(
          id = 'streetaddress_write',
          desc = 'Read and update your verified street addresses',
          icon = 'http://idp.com:9000/static/icons/streetaddress_write.png')
      scope.put()    
      logging.info('Scope \' %s \'put under key: %s' % (scope.id,scope.key()))

      return